package com.qidian.mes.produce.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidian.common.pojo.MESResult;
import com.qidian.mes.pojo.Material;
import com.qidian.mes.pojo.WorkOrder;
import com.qidian.mes.produce.mapper.WorkOrderMapper;
import com.qidian.mes.produce.service.WorkOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author 陈俊成
 * @Company ccc
 * @Description
 * @Time 2024/10/23 16:34
 */
@Service
public class WorkOrderServiceImpl implements WorkOrderService {
    @Autowired
    WorkOrderMapper workOrderMapper;
    @Override
    public MESResult queryList(WorkOrder workOrder, int page, int limit) {
        PageHelper.startPage(page,limit);

        List<WorkOrder> workOrders =workOrderMapper.queryList(workOrder);
        System.out.println("++++++++++++++++++++++++++++++++++++"+workOrders);

        PageInfo<WorkOrder> workOrderPageInfo = new PageInfo<>(workOrders);
        return MESResult.success(workOrderPageInfo);

    }

    @Override
    public MESResult addWorkOrder(WorkOrder workOrder) {
        return MESResult.success(workOrderMapper.addWorkOrder(workOrder));
    }

    @Override
    public MESResult getPrimary(int workOrderRelId) {
        return MESResult.success(workOrderMapper.getPrimary(workOrderRelId));
    }

    @Override
    public MESResult primary(WorkOrder workOrder) {
        return MESResult.success(workOrderMapper.updateWorkOrder(workOrder));
    }

    @Override
    public MESResult surePrimary(WorkOrder workOrder) {
        return MESResult.success(workOrderMapper.updateStatusBeSure(workOrder));
    }

    @Override
    public MESResult deleteWorkOrder(int workOrderRelId) {
        return MESResult.success(workOrderMapper.updateStatusOfDelete(workOrderRelId));
    }

    @Override
    public MESResult deleteWorkOrders(List<WorkOrder> workOrders) {
        for (int i=0;i<workOrders.size();i++){
            workOrderMapper.updateStatusOfDelete(workOrders.get(i).getWorkOrderRelId());
        }
        return MESResult.success();
    }
}
